package com.errorfinding.rabbitmq.five;

import com.errorfinding.rabbitmq.util.RabbitMqUtils;
import com.rabbitmq.client.Channel;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

/**
 * 生产者
 * 发消息 给交换机
 * 扇出模式 fauout 发布订阅模式
 */
public class EmitLog {

    public static final String exchange_name = "logs";

    public static void main(String[] args) throws IOException, TimeoutException {
        //创建信道
        Channel channel = RabbitMqUtils.getChannel();
        //声明交换机
        channel.exchangeDeclare(exchange_name,"fanout");

        Scanner scanner =  new Scanner(System.in);

        while (scanner.hasNext()){
            String message =scanner.next();
            channel.basicPublish(exchange_name,"",null,message.getBytes("utf-8"));
            System.out.println("生产者发出消息----"+message);
        }
    }
}
